#include <glib.h>

static void _list_str_print_func(gpointer data, gpointer user_data)
{
    g_print("user_data is: %s, data is: %s \n", (gchar *)user_data, (gchar*)data);
}

static gpointer _list_str_copy_deep (gconstpointer value, gpointer data)
{
  return (gpointer)g_strdup((const gchar *)value);
}

static void _list_str_free_func(gpointer data)
{
    g_free((gchar *)data);
}

gint main(gint argc, gchar **argv)
{
    GList *list = NULL;
    GList *list2 = NULL;
    GList *list3 = NULL;

    gchar *str1 = NULL;
    gchar *str2 = NULL;

    str1 = g_strdup("hello");
    str2 = g_strdup("world");
    
    list = g_list_append(list, (gpointer)str1);
    list = g_list_append(list, (gpointer)str2);

    g_print("===test copy===\n");

    list2 = g_list_copy(list);

    g_list_foreach(list, _list_str_print_func, (gchar *)"list");
    g_list_foreach(list2, _list_str_print_func, (gchar *)"list2");

    g_print("===test deep copy===\n");

    list3 = g_list_copy_deep(list, _list_str_copy_deep, NULL);

    g_list_foreach(list, _list_str_print_func, (gchar *)"list");
    g_list_foreach(list2, _list_str_print_func, (gchar *)"list2");
    g_list_foreach(list3, _list_str_print_func, (gchar *)"list3");

    g_list_free_full(list, _list_str_free_func);
    g_list_free(list2);  // #ERROR!!!:  g_list_free_full(list2, _list_str_free_func);
    g_list_free_full(list3, _list_str_free_func);

    return 0;
}